<!DOCTYPE html>
<html>
<head lang="en">
	<meta charset="UTF-8">
<title>带关闭按钮的滚动广告</title>
<style type="text/css">
#main{ text-align:center;}
#float{
	position:absolute;
	left:30px;
	top:60px; 
	z-index:1;
	}
#close{
	position:absolute;
	top:60px;
	left:134px;
	z-index:2;
	cursor:pointer;
}
</style>

</head>
<body>
<div id="close" onClick="adv_close()"><img src="images/close.jpg"></div>
<div id="float"><img src="images/advpic.jpg"></div>
<div id="main"><img src="images/contentpic.jpg"></div>
<script type="text/javascript">
	var floattop;
	var floatleft;
	var thisfloat;
	var closetop;
	var closeleft;
	var thisclose;
	function inix(){
		thisfloat=document.getElementById("float");
		thisclose=document.getElementById("close");
		if(thisfloat.currentStyle){
			floattop=parseInt(thisfloat.currentStyle.top);
			floatleft=parseInt(thisfloat.currentStyle.left);
			closetop=parseInt(thisclose.currentStyle.top);
			closeleft=parseInt(thisclose.currentStyle.left);
		}else{
			floattop=parseInt(document.defaultView.getComputedStyle(thisfloat,null).top);
			floatleft=parseInt(document.defaultView.getComputedStyle(thisfloat,null).left);
			closetop=parseInt(document.defaultView.getComputedStyle(thisclose,null).top);
			closeleft=parseInt(document.defaultView.getComputedStyle(thisclose,null).left);
		}
		
	}
	function move(){
		var sTop=parseInt(document.documentElement.scrollTop||document.body.scrollTop);
		var sLeft=parseInt(document.documentElement.scrollLeft||document.body.scrollLeft);
		thisfloat.style.top=floattop+sTop+"px";
		thisfloat.style.left=floatleft+sLeft+"px";
		thisclose.style.top=closetop+sTop+"px";
		thisclose.style.left=closeleft+sLeft+"px";
	}
	window.onload=inix;
	window.onscroll=move;
	function adv_close(){
		document.getElementById("float").style.display="none";
		document.getElementById("close").style.display="none";
	}
</script>
</body>

</html>
